function [ret] = haar_evaluate_feature(IMG,x,y,explorer_x,explorer_y, feature)

switch feature
	case 1
		ret = get_rec_sum(IMG,x,y+ceil((explorer_y-y)/2),explorer_x,explorer_y) - get_rec_sum(IMG,x,y,explorer_x,y+floor((explorer_y-y)/2));
	case 2
		ret = get_rec_sum(IMG,x+ceil((explorer_x-x)/2),y,explorer_x,explorer_y) - get_rec_sum(IMG,x,y,x+floor((explorer_x-x)/2),explorer_y);
	case 3
		ret = get_rec_sum(IMG,x,y+ceil((explorer_y-y)*1/3),explorer_x,y+floor((explorer_y-y)*2/3)) - get_rec_sum(IMG,x,y,explorer_x,y+floor((explorer_y-y)/3)) - get_rec_sum(IMG,x,y+ceil((explorer_y-y)*2/3),explorer_x,explorer_y);
	case 4
		ret = get_rec_sum(IMG,x+ceil((explorer_x-x)/3),y,x + floor((explorer_x-x)*2/3),explorer_y) - get_rec_sum(IMG,x,y,x+floor((explorer_x-x)/3),explorer_y) - get_rec_sum(IMG,x+ceil((explorer_x-x)*2/3),y,explorer_x,explorer_y);
	case 5
		ret = get_rec_sum(IMG,x,y,explorer_x,explorer_y) - 2*get_rec_sum(IMG,x+ceil((explorer_x-x)/2),y,explorer_x,y+floor((explorer_y-y)/2)) - 2*get_rec_sum(IMG,x,y+ceil((explorer_y-y)/2),x+floor((explorer_x-x)/2),explorer_y);
	otherwise
		warning('Unexpected feature type');
end

function [result] = get_rec_sum(IMG,x,y,explorer_x,explorer_y)
xa = x - 1;
ya = y - 1;

xb = explorer_x;
yb = ya;

xc = xa;
yc = explorer_y;

value_a = 0;
value_b = 0;
value_c = 0;

if xa >=1 && ya >= 1
        value_a = squeeze(IMG(xa,ya,:));
end
if yb >= 1
        value_b = squeeze(IMG(xb,yb,:));
end
if xc >=1
        value_c = squeeze(IMG(xc,yc,:));
end

result = squeeze(IMG(explorer_x,explorer_y,:)) - value_b - value_c + value_a;

